package pl.prv.polanie.client.dto;

import java.util.Comparator;

import com.google.gwt.user.client.rpc.IsSerializable;




/**
 * SemestersYearGroupsDTO entity. @author MyEclipse Persistence Tools
 */

public class CSVSemestersYearGroupsDTO extends java.lang.Object implements IsSerializable, ICSVDTO {


    // Fields    
	private long id;
	
    private String semester;
    private String yearGroupName;
    private Integer studentsNumber;
    
    
    private boolean highlighted;
    
    public static final int SORT_CONST__YEAR_GROUP_NAME = 0;
    public static final int SORT_CONST__STUDENTS_NUMBER = 1;
    public static final int SORT_CONST__SEMESTER = 2;

    public static final int SORT_CONST__ID = 3;


    // Constructors

    public CSVSemestersYearGroupsDTO(long id, String semester,
			String yearGroupName, Integer studentsNumber) {
		super();
		this.id = id;
		this.semester = semester;
		this.yearGroupName = yearGroupName;
		this.studentsNumber = studentsNumber;
	}


	/** default constructor */
    public CSVSemestersYearGroupsDTO() {
    }

    
    /** full constructor */
    


   
    // Property accessors




	public Integer getStudentsNumber() {
        return this.studentsNumber;
    }
    
    public void setStudentsNumber(Integer studentsNumber) {
        this.studentsNumber = studentsNumber;
    }
   

    public String toLabel() {
    	String result;
    	result = "" + yearGroupName + " [" + studentsNumber + "] " + semester;
    	return result;
    }

    public String toLabelShort() {
    	String result;
    	result = "" + yearGroupName + " [" + studentsNumber + "]";
    	return result;
    }

	public String getSemester() {
		return semester;
	}


	public void setSemester(String semester) {
		this.semester = semester;
	}


	public String getYearGroupName() {
		return yearGroupName;
	}


	public void setYearGroupName(String yearGroupName) {
		this.yearGroupName = yearGroupName;
	}


	public long getId() {
		return id;
	}


	public void setId(long id) {
		this.id = id;
	}
	
	
	public String getField(int col) {
		if (col == SORT_CONST__ID) {
			return "" + getId();
		} else if (col == SORT_CONST__SEMESTER) {
			return "" + getSemester();
		} else if (col == SORT_CONST__YEAR_GROUP_NAME) {
			return "" + getYearGroupName();
		} else if (col == SORT_CONST__STUDENTS_NUMBER) {
			return "" + getStudentsNumber();
		}
		return "no field";
	}


	@SuppressWarnings("unchecked")
	public static Comparator getComparator(final int colIndex) {
		Comparator cmp = new Comparator() {
			public int compare(Object o1, Object o2) {

//			    final int BEFORE = -1;
			    final int EQUAL = 0;
//			    final int AFTER = 1;
			    
			    CSVSemestersYearGroupsDTO obj1;
			    CSVSemestersYearGroupsDTO obj2;
			    if (o1 instanceof CSVSemestersYearGroupsDTO && o2 instanceof CSVSemestersYearGroupsDTO) {

					obj1 = (CSVSemestersYearGroupsDTO) o1;
					obj2 = (CSVSemestersYearGroupsDTO) o2;
					
					//this optimization is usually worthwhile, and can
					//always be added
					if ( obj1 == obj2 ) return EQUAL;

					//primitive numbers follow this form
					if (colIndex == SORT_CONST__ID) {
						Long l1 = new Long(obj1.getId());
						Long l2 = new Long(obj2.getId());
						return l1.compareTo(l2);
					} else if (colIndex == SORT_CONST__SEMESTER) {
						return obj1.getSemester().compareTo(obj2.getSemester());
					} else if (colIndex == SORT_CONST__YEAR_GROUP_NAME) {
						return obj1.getYearGroupName().compareTo(obj2.getYearGroupName());
					} else if (colIndex == SORT_CONST__STUDENTS_NUMBER) {
						return obj1.getStudentsNumber().compareTo(obj2.getStudentsNumber());
					}
					
				};
				return EQUAL;
			}
		};

		return cmp;
	}

	
	
	
	

	public boolean isHighlighted() {
		return highlighted;
	}



	public void setHighlighted(boolean highlighted) {
		this.highlighted = highlighted;
	}
	

}